package com.seed.core.pojo.controller;

import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
import com.seed.core.pojo.entity.SeedBaseEntity;
import com.seed.core.pojo.manager.SeedApiManager;
import com.seed.core.pojo.service.SeedApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author gchiaway
 * 日期: 2020-02-22
 * 时间: 17:27
 */
@Slf4j
public class SeedApiController<Service extends SeedApiService<Entity>, Manager extends SeedApiManager<Entity>, Entity extends SeedBaseEntity> extends SeedBaseController {


    @Autowired
    protected Manager baseManager;
    @Autowired
    protected Service baseService;


    protected Class<Service> serviceClass = currentServiceClass();
    protected Class<Manager> managerClass = currentManagerClass();
    protected Class<Entity> realEntityClass = currentModelClass();

    protected Class<Service> currentServiceClass() {
        return (Class<Service>) ReflectionKit.getSuperClassGenericType(getClass(), SeedApiController.class, 0);
    }

    protected Class<Manager> currentManagerClass() {
        return (Class<Manager>) ReflectionKit.getSuperClassGenericType(getClass(), SeedApiController.class, 1);
    }

    protected Class<Entity> currentModelClass() {
        return (Class<Entity>) ReflectionKit.getSuperClassGenericType(getClass(), SeedApiController.class, 2);
    }

}
